//
//  LOLFirstPageCell.m
//  LOL_Little_Box
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LOLFirstPageCell.h"
#import "LOLImageView.h"
#import "LOLLabel.h"
#import "UIImageView+WebCache.h"
#import "LWSCoculateSize.h"

@interface LOLFirstPageCell ()

@property (nonatomic , retain)LOLImageView *imageShow;
@property (nonatomic , retain)LOLLabel *labelTitle;
@property (nonatomic , retain)LOLLabel *labelSummary;
@property (nonatomic , retain)LOLLabel *labelTimeLine;

@end

@implementation LOLFirstPageCell

- (void)setModel:(LOLModelFirstCell *)model{
    _model = model;
    [_imageShow sd_setImageWithURL:[NSURL URLWithString:_model.image_url_small] placeholderImage:[UIImage imageNamed:@"firstPager_cell_image_holder.jpg"]];
    _labelTitle.text = _model.title;
    _labelSummary.text = _model.summary;
    /**可能需要修改 */
    _labelTimeLine.text = [_model.publication_date substringToIndex:11];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageShow = [[LOLImageView alloc]initWithFrame:CGRectZero];
        self.labelTitle = [[LOLLabel alloc]initWithFrame:CGRectZero];
        self.labelSummary = [[LOLLabel alloc]initWithFrame:CGRectZero];
        self.labelTimeLine = [[LOLLabel alloc]initWithFrame:CGRectZero];
        
        /**设置风格字体，颜色 */
        self.labelTitle.font = [UIFont boldSystemFontOfSize:14.0];
        self.labelSummary.font = [UIFont systemFontOfSize:12.0];
        self.labelTimeLine.font = [UIFont systemFontOfSize:12.0];
        
        self.labelSummary.textColor = [UIColor darkGrayColor];
        self.labelTimeLine.textColor = [UIColor darkGrayColor];
        self.labelTitle.numberOfLines = 0;
        self.labelSummary.numberOfLines = 0;
        
        /**添加到渲染视图上 */
        [self.contentView addSubview:self.imageShow];
        [self.contentView addSubview:self.labelSummary];
        [self.contentView addSubview:self.labelTimeLine];
        [self.contentView addSubview:self.labelTitle];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
   /**动态调整尺寸 */
    CGFloat height = self.contentView.frame.size.height;
    UIImage *image = [UIImage imageNamed:@"firstPager_cell_image_holder.jpg"];
    CGRect frame = CGRectMake(10, 10,(image.size.height / (height - 20)) * image.size.width, height - 20);
    frame.origin.x += 10 + frame.size.width;
    frame.size.width = self.contentView.frame.size.width - frame.origin.x - 10;
    frame.size.height = [LWSCoculateSize getCurrentLabelHeightByLabelText:self.labelTitle.text Font:self.labelTitle.font LabelWidth:frame.size.width];
    self.labelTitle.frame = frame;
    
    frame.origin.y += frame.size.height + 10;
    frame.size.height = [LWSCoculateSize getCurrentLabelHeightByLabelText:self.labelSummary.text Font:self.labelSummary.font LabelWidth:frame.size.width];
    self.labelSummary.frame = frame;
    
    /**根据cell的底部坐标获得时间线的位置(高度确定) */
    frame.size.height = 15;
    frame.size.width = [LWSCoculateSize getCurrentLabelWidthByLabelText:self.labelTimeLine.text Font:self.labelTimeLine.font LabelHeight:frame.size.height];
    frame.origin.y = self.contentView.frame.size.height - frame.size.height - 10;
    frame.origin.x = self.contentView.frame.size.width - frame.size.width - 10;
    self.labelTimeLine.frame = frame;
}

@end
